package basic_1021;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner=new Scanner(System.in);
		
		int N=scanner.nextInt();
		String[]ids=new String[N];
		
		
		for(int i=0;i<N;i++) {
			ids[i]=scanner.next();
		}
		
		scanner.close();
		int count=0;
		for(String id:ids) {
			if(!isRight(id)) {
				count++;
				System.out.println(id);
			}
		}
		if(count==0) {
			System.out.println("All passed");
		}
	}
	
	static boolean isRight(String id) {
		int[] num=new int[17];
		int[]power={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
		
		int sum=0;
		for(int i=0;i<17;i++) {
			num[i]=id.charAt(i)-'0';
			sum+=num[i]*power[i];
		}
		
		int Z=sum%11;
		char[] M= {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
		
		return id.charAt(17)==M[Z];
	}
}
